/**
 * JAVACC DEMO 1.0
 */
package com.apache.info.service.plugins;

import com.apache.api.vo.ParamsVo;
import com.apache.cache.util.Validator;
import com.apache.info.entity.PubInfoStatistics;
import com.apache.info.manager.InfoReleaseManager;
import com.apache.info.manager.PubInfoStatisticsManager;

import java.util.Map;

/**
 * description:  动态插入信息
 *
 * @author Hou Dayu 创建时间：2016-8-29
 */
public class InsertDynamicInfoPluginImpl extends AbstractInfoReleasePlugin {

    private InfoReleaseManager InfoReleaseManager;

    private PubInfoStatisticsManager pubInfoStatisticsManager;

    /**
     * TODO 动态插入信息插件实现.
     *
     * @see com.apache.info.service.plugins.AbstractInfoReleasePlugin#doInvoke(ParamsVo)
     */
    protected Object doInvoke(ParamsVo vo) {
        String mark = InfoReleaseManager.saveInfo(vo);
        if ("true".equals(mark) && "true"
                .equals(String.valueOf(vo.getParams("flagInfoStatistics")))) {//添加统计信息
            Map map = vo.getParams();
            ParamsVo pvo = new ParamsVo();
            if (Validator.isNotNull(String.valueOf(map.get("infoId")))) {
                PubInfoStatistics ps = new PubInfoStatistics();
                ps.setInfoId(Validator.generate());
                ps.setInfoUser(String.valueOf(map.get("createUser")));
                ps.setObjId(String.valueOf(map.get("infoId")));
                ps.setSortId(String.valueOf(vo.getParams("sortCode")));
                pvo.setObj(ps);
                pubInfoStatisticsManager.saveInfo(pvo);
            }
        }
        return mark;
    }

    public void setInfoReleaseManager(InfoReleaseManager infoReleaseManager) {
        InfoReleaseManager = infoReleaseManager;
    }

    public void setPubInfoStatisticsManager(PubInfoStatisticsManager pubInfoStatisticsManager) {
        this.pubInfoStatisticsManager = pubInfoStatisticsManager;
    }
}
